minios: reverse layering of xc vs minios fd close
authorKeir Fraser <keir@xen.org>
Fri, 3 Dec 2010 06:37:48 +0000 (06:37 +0000)
committerKeir Fraser <keir@xen.org>
Fri, 3 Dec 2010 06:37:48 +0000 (06:37 +0000)
Having minios close() call back into the libxc core close routines is
backwards and unexpected. On every other OS the libxc core close
routine calls close().

Export minios specific functions from the minios libxc code to
implement fd closing for each type of xc file handle and simply call
close() in the core close routine.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
extras/mini-os/lib/sys.c
tools/libxc/xc_minios.c

index 42681742b8e999c2308fb3eff9d7ce916000f463..b127996df5cef19bd49d5bf8364547fc709c1917 100644 (file)
     }
 
 #define NOFILE 32
-extern int xc_evtchn_close(int fd);
-struct xc_interface;
-extern int xc_interface_close_core(struct xc_interface*, int fd);
-extern int xc_gnttab_close(int fd);
+extern void minios_interface_close_fd(int fd);
+extern void minios_evtchn_close_fd(int fd);
+extern void minios_gnttab_close_fd(int fd);
 
 pthread_mutex_t fd_lock = PTHREAD_MUTEX_INITIALIZER;
 struct file files[NOFILE] = {
@@ -414,13 +413,13 @@ int close(int fd)
        }
 #endif
        case FTYPE_XC:
-           xc_interface_close_core(0,fd);
+           minios_interface_close_fd(fd);
            return 0;
        case FTYPE_EVTCHN:
-            xc_evtchn_close(fd);
+           minios_evtchn_close_fd(fd);
             return 0;
        case FTYPE_GNTMAP:
-           xc_gnttab_close(fd);
+           minios_gnttab_close_fd(fd);
            return 0;
        case FTYPE_TAP:
            shutdown_netfront(files[fd].tap.dev);
index 60f28d36fcd18422bc8740816f892b99bdd890f2..774e1debc61b812b51c429206163a9ab209edf67 100644 (file)
 
 #include "xc_private.h"
 
+void minios_interface_close_fd(int fd);
+void minios_evtchn_close_fd(int fd);
+void minios_gnttab_close_fd(int fd);
+
 extern struct wait_queue_head event_queue;
 
 int xc_interface_open_core(xc_interface *xch)
@@ -48,9 +52,13 @@ int xc_interface_open_core(xc_interface *xch)
 }
 
 int xc_interface_close_core(xc_interface *xch, int fd)
+{
+    return close(fd);
+}
+
+void minios_interface_close_fd(int fd)
 {
     files[fd].type = FTYPE_NONE;
-    return 0;
 }
 
 void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot,
@@ -173,13 +181,17 @@ int xc_evtchn_open(void)
 }
 
 int xc_evtchn_close(int xce_handle)
+{
+    return close(xce_handle);
+}
+
+void minios_evtchn_close_fd(int fd)
 {
     int i;
     for (i = 0; i < MAX_EVTCHN_PORTS; i++)
-        if (files[xce_handle].evtchn.ports[i].bound)
-            unbind_evtchn(files[xce_handle].evtchn.ports[i].port);
-    files[xce_handle].type = FTYPE_NONE;
-    return 0;
+        if (files[fd].evtchn.ports[i].bound)
+            unbind_evtchn(files[fd].evtchn.ports[i].port);
+    files[fd].type = FTYPE_NONE;
 }
 
 int xc_evtchn_fd(int xce_handle)
@@ -370,9 +382,13 @@ int xc_gnttab_open(xc_interface *xch)
 
 int xc_gnttab_close(xc_interface *xch, int xcg_handle)
 {
-    gntmap_fini(&files[xcg_handle].gntmap);
-    files[xcg_handle].type = FTYPE_NONE;
-    return 0;
+    return close(xcg_handle);
+}
+
+void minios_gnttab_close_fd(int fd)
+{
+    gntmap_fini(&files[fd].gntmap);
+    files[fd].type = FTYPE_NONE;
 }
 
 void *xc_gnttab_map_grant_ref(xc_interface *xch, int xcg_handle,